/**
 * Copyright © 2011 looty - Textoo
 * @link http://www.textoo.org
 * @link http://code.google.com/p/textoo/
 * @author lab9 - Bertrand Larrieu
 * @mail lab9.fr@gmail.com
 * @version 2.0
 */

package org.looty.core.textoo.render 
{
	import flash.display.*;
	import flash.text.*;
	import org.looty.core.textoo.format.*;

	public class BitmapRenderer extends AbstractTextooRenderer implements ITextooRenderer
	{
		
		private var _textField				:TextField;		
		private var _container				:Sprite;
		
		public function BitmapRenderer() 
		{
			super(2);
			_textField = createTextField();
			
			_container = new Sprite();
			_container.addChild(_textField);
		}
		
		override protected function applyProperties(textField:TextField, props:TextooProps):void 
		{
			_textField.text = "";
			super.applyProperties(textField, props);
		}
		
		public function render(props:TextooProps):RenderData 
		{
			applyProperties(_textField, props);
			
			//TODO: bitmap cut to 256x256 ?
			//implements MouseInteraction
			
			var bmd:BitmapData = new BitmapData(props.size.width, props.size.height, true, 0);
			bmd.draw(_container);
			
			_textField.text = "";
			
			return new RenderData(Vector.<DisplayObject>([new Bitmap(bmd, PixelSnapping.ALWAYS)]));
		}
		
		override public function dispose():void
		{
			_container.removeChild(_textField);
			_container = null;
			_textField = null;
		}
		
		
	}

}